<!DOCTYPE html>
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<html><head>

<title>商品信息</title>

<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta charset="UTF-8">
<link rel="stylesheet" href="../../resource/weui.min.css"/>
<link rel="stylesheet" href="../../resource/example.css"/>
<script src="../../script/api.js"></script>
<script src="../../resource/jquery-1.js"></script>
<script type="text/javascript" src="../../resource/wap_common.js"></script>
<script type="text/javascript" src="../../resource/common.js"></script>
<script type="text/javascript" src="../../resource/jweixin-1_002.js"></script>
<script type="text/javascript" src="../../resource/jweixin-1.js"></script>
<script src="../../script/api.js"></script>
<link rel="stylesheet" href="../../resource/jinsuistyle.css" />
<script type="text/javascript">
//var reg = new RegExp("/^([1-9]\d{0,15}|0)(\.\d{1,2})?$/");

     apiready=function(){
       var header = $api.byId('jsheader');
   		if(api.systemType=='ios'){
   			$api.fixIos7Bar(header);
   		}
// 		else{
// 			$api.fixStatusBar(header);
// 		}
        var codeStr = api.pageParam.codeStr;
        //console.info(codeStr);
		//api.alert({msg:'http://wechat.scjinsui.com/weixin/fpkj/merid0.do?openid='+codeStr});
		console.log('http://wechat.scjinsui.com/weixin/fpkj/merid0.do?openid='+codeStr);
        api.ajax({
            //url: 'http://192.168.76.50:8181/fpkj/merid0.do?openid='+codeStr,
            url: 'http://wechat.scjinsui.com/weixin/fpkj/merid0.do?openid='+codeStr,
            method: 'get',
            dataTpye: 'json',
        }, function(ret,err){
            //console.log("---->"+ret);
            if (ret) {
                document.getElementById("merid").value = ret.merid;
                document.getElementById("ggxh").value = ret.ggxh;
                document.getElementById("jldw").value = ret.jldw;
                document.getElementById("slv").value = ret.slv;
                document.getElementById("key").value = ret.key;
                document.getElementById("openid").value = ret.openid;
                document.getElementById("scaned").value = ret.scaned;
                document.getElementById("fno").value = ret.fno;
                document.getElementById("produce").value = ret.produce;
                document.getElementById("qymc").value = ret.qymc;
                document.getElementById("fno").value = ret.fno;
                merid = ret.merid;
                ggxh = ret.ggxh;
                jldw = ret.jldw;
                slv = ret.slv;
                key = ret.key;
                openid = ret.openid;
                scaned = ret.scaned;
                fno = ret.fno;
                produce = ret.produce;
                qymc = ret.qymc;
                fno = ret.fno;
                invoiceMerId = ret.invoiceMerId;
                terminalId = ret.terminalId;
                //document.getElementById("fno").value = ret.fno;
                if(ret.je!="-1"){
                	document.getElementById("je").value = ret.je;
                }
                if(ret.merid=="-1"){
                	$("#tip0").show();
                }
                if(ret.qymc==null||ret.qymc==""){
                	$("#tip0").show();
                	$("#kj").hide();
                }
                if(ret.merid!="-1"){
                    var state = $api.getStorage('state');
                	if(state=="111"){
    					    	$("#payBtn").show();
    					    	$("#tip0").hide();
    					    	$("#saveBtn").hide();
    				}
                }
		    } else {
		        api.alert({msg:'网络异常'});
		    }
        });
     }

	var reg = /^[0-9]+([.]{1}[0-9]{1,2})?$/;

	function pay(){
		$("#loadingToast").show();
		var je = $("#je").val();
		var bz = $("#bz").val();
		if(je == null || je == '' || !reg.test(je) || je == '0'||je == '0.0'|| je == '0.00'){
			$("#loadingToast").hide();
			alert("请正确输入金额！");
			return;
		}
		if(bz != null && bz!= '' && bz.length > 100){
			$("#loadingToast").hide();
			alert("备注信息过长！");
			return;
		}
		api.ajax({
    		url: 'http://wechat.scjinsui.com/weixin/wxPay/getTokenId.do',
   			method: 'post',
    		data: {
        		values: {
            	   mch_id : merid,//商户号
	        	   body : produce,//商品描述
	        	   sub_openid:openid,
	        	   total_fee:je,
	        	   attach:$("#bz").val(),//备注
	        	   invoiceMerId :invoiceMerId.replace(/\+/g, '%2B'),
	        	   terminalId :terminalId.replace(/\+/g, '%2B'),
	        	   shmc:qymc,
	        	   ggxh:ggxh,
	        	   jldw:jldw,
	        		slv:slv,
	        		key:key,
	        		//key:'732c7510f7f939b073d1aee8a7ad8d3f',
	        		fno :fno//流水号
		        }
		    }
		}, function(ret, err) {
		    if (ret) {
		    //api.alert({msg:ret.token_id});
		    console.log(ret.token_id);
		        if(ret.success==true){
	           		//window.location.href='https://pay.swiftpass.cn/pay/jspay?showwxpaytitle=1&token_id='+data.token_id;

	           		api.ajax({
	                       url:'https://pay.swiftpass.cn/pay/jspay?showwxpaytitle=1&token_id='+ret.token_id,
	                       method:'get'
                       },function(ret,err){
							if(ret){

							}else{
								api.alert({msg:'网络异常'});
							}
                       });
	           	}else{
	           		$("#loadingToast").hide();
	           		api.alert({msg:'提交订单失败，错误信息：' + ret.rst});
	           		//alert("提交订单失败，错误信息：" + ret.rst);
	           	}
		    } else {
		       console.log("服务请求错误,请联系管理员!");
		       api.alert({msg:'网络异常'});
		    }
		});



	}

	var merid;
	var produce;
	var openid;
	var kpid;
	var invoiceMerId;
	var terminalId;
	var qymc;
	var ggxh;
	var jldw;
	var slv;
	var key;
	var fno;

	function fpkj(){
		var je = $("#je").val();
		var bz = $("#bz").val();
		if(je == null || je == '' || !reg.test(je) || je == '0'||je == '0.0'|| je == '0.00'){
			$("#loadingToast").hide();
			api.alert({msg:'请正确输入金额！'});
			return;
		}
		if(bz != null && bz!= '' && bz.length > 100){
			$("#loadingToast").hide();
			api.alert({msg:'备注信息过长！'});
			return;
		}
		$("#invoicemerid").val(invoiceMerId.replace(/\+/g, '%2B'));
		$("#terminalid").val(terminalId.replace(/\+/g, '%2B'));
		$("#loadingToast").show();
		api.openWin({
	        name: 'gotoKp',
	        url: './Invoice_qyxz.html',
	        pageParam:{
	        	merid :  merid,
				produce: $("#produce").val(),
				openid: openid,
				kpid: kpid,
				invoiceMerId: invoiceMerId,
				terminalId: terminalId,
				qymc: qymc,
				ggxh: ggxh,
				jldw: jldw,
				slv: slv,
				key: key,
				fno: fno,
				 je : $("#je").val(),
				 bz : $("#bz").val(),
				 scaned:$("#scaned").val()
	        }
        });
		api.closeWin();
	}

</script>
</head>
<body>
  <div style="background: #27a8fa" id="jsheader">
			<nav id="jsnav">
					<a id="jsleft" tapmode="" onclick="api.closeWin();">
							<span>返回</span>
					</a>
					<div id="jsmiddle">
							<strong id="jstitle">极速开票</strong>
					</div>
					<a id="jsright">
						<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
					</a>
			</nav>
	</div>
		<div class="paddingtop70">&nbsp;</div>
<style type="text/css">
body {
	font-family:"微软雅黑";
    font-weight: normal;
}
</style>

	<form id="chsQy" > <!-- action="http://wechat.scjinsui.com/weixin/fpkj/chsQy.do" -->
	<input type="hidden" name="invoicemerid" id="invoicemerid"/>
	<input type="hidden" name="terminalid" id="terminalid"/>
	<input id="merid" type="hidden" name="merchant" />
	<input id="ggxh" type="hidden" name="ggxh" />
	<input id="jldw" type="hidden" name="jldw" />
	<input id="slv" type="hidden" name="slv" />
	<input id="key" type="hidden" name="key" />
	<input id="openid" type="hidden" name="openid" />
	<input id="scaned" type="hidden" name="scaned" />
	<input id="fno" type="hidden" name="fno" />

	<div class="weui-cells__title">商家名称</div>
	        <div class="weui-cells">
	            <div class="weui-cell">
	                <div class="weui-cell__bd">
	                    <input class="weui-input" id="qymc" name="shmc" type="text" readonly="readonly" />
	                </div>
	            </div>
	     </div>

	 <div class="weui-cells__title">商品名称</div>
	        <div class="weui-cells">
	            <div class="weui-cell">
	                <div class="weui-cell__bd">
	                    <input class="weui-input" id="produce" name="produce" type="text"  />
	                </div>
	            </div>
	     </div>

	<div class="weui-cells__title">金   额</div>
	        <div class="weui-cells">
	            <div class="weui-cell">
	                <div class="weui-cell__bd">

	                    <input id="je" name="amount" class="weui-input" type="text" placeholder="请输入金额（必填）"/>


	                </div>
	            </div>
	        </div>
	        <div class="weui-cells__title">备   注</div>
	        <div class="weui-cells">
	            <div class="weui-cell">
	                <div class="weui-cell__bd">
	                    <input id="bz" name="bz" class="weui-input" type="text" placeholder="请输入备注（选填）"/>
	                </div>
	            </div>
	        </div>
	<div class="weui-cells__title"></div>
	<div class="weui-cells__title"></div>
	<div class="weui-cells__title"></div>
	<div class="weui-cells__title"></div>

		<div style="display: none" id="tip0" class="weui-cells__title">提示：该商家可以开票，不能在线支付！</div>


	<div id="kj" class="page__bd page__bd_spacing">
		<br />
		<a href="javascript:;" style="display: none" id="payBtn" class="weui-btn weui-btn_primary" onclick="pay();">在线支付</a>
	    <a href="javascript:;" id="saveBtn" style="background-color:#27a8fa" class="weui-btn weui-btn_default" onclick="fpkj();">发票开具</a>
	<!--style="background-color:#eaeaea"-->
	</div>
	</form>


	<div style="display: none" id="tip1" class="weui-msg">
		<div class="weui-msg__icon-area">
			<div class="icon-box">
				<i class="weui-icon-info weui-icon_msg"></i>
			</div>
		</div>
		<div class="weui-msg__text-area">
			<h2 class="weui-msg__title">提示：未找到相关商家信息！</h2>
		</div>
		<div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="./main.html" class="weui-btn weui-btn_default">返   回</a>
            </p>
        </div>
	</div>



   <div id="loadingToast" style="display:none;">
        <div class="weui-mask_transparent"></div>
        <div class="weui-toast">
            <i class="weui-loading weui-icon_toast"></i>
            <p class="weui-toast__content">数据加载中..</p>
        </div>
	</div>

<div style="text-align: center;bottom: 12px;z-index: 999;left: 0;right:0;margin-top: 10%" >
	<p style="text-align: center"><a  style="color:#777;font-size:12px;text-align: center">四川航天金穗高技术有限公司</a></p>
</div>
</body></html>
